package com.bolang.onlycode.demo.unsafe;

import java.lang.reflect.Field;

public class Unsafe {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
        // 将字段的访问权限设置为true
        field.setAccessible(true);
        // 因为theUnsafe字段在Unsafe类中是一个静态字段，所以通过Field.get()获取字段值时，可以传null获取
        sun.misc.Unsafe unsafe = (sun.misc.Unsafe) field.get(null);
    }
}
